<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>JavaScripTools Manual</title>
    <link rel="stylesheet" type="text/css" href="../../css/style.css">
</head>

<body>
<br>
<h1>JavaScripTools Manual</h1>
<h2>JavaScripTools</h2>
<h3>Working with dates</h3>
<p>There are several functions to perform operations on dates.</p>
<p>The best place to look at the 
<a href="../api/script_JavaScriptUtil.html">JavaScriptUtil API documentation</a>,
that have a complete list of functions. Here, the idea is not to replicate that
information, but to give a basic understanding.</p>
<p>Most of the date manipulation functions use a field. Fields are represented by
<a href="JavaScriptUtil_constants.html">contants</a>. Whenever a field is used and
not informed, the default assumed is JST_FIELD_DAY.</p>
<br>
<p>The
<a href="../api/JavaScriptUtil_functions.html#dateAdd">dateAdd</a> and
<a href="../api/JavaScriptUtil_functions.html#truncDate">truncDate</a>
functions change a given date, according to a field.</p>
Examples:
<pre>var date = new Date(2000, 9, 1, 11, 30, 0); (Oct 1, 2000 11:30:07 - month starts with 0)
dateAdd(date, 1) -> Oct 2, 2000 11:30:07
dateAdd(date, 1, JST_FIELD_MONTH) -> Nov 1, 2000 11:30:07
dateAdd(date, -1) -> Sep 30, 2000 11:30:07
truncDate(date) -> Oct 1, 2000 00:00:00
truncDate(date, JST_FIELD_HOUR) -> Oct 1, 2000 11:00:00
truncDate(date, JST_FIELD_MINUTE) -> Oct 1, 2000 11:30:00
</pre><br>

<p>The
<a href="../api/JavaScriptUtil_functions.html#dateDiff">dateDiff</a>
function compares two dates, given a field, and returns the difference.</p>
Examples:
<pre>var date1 = new Date(2000, 9, 1); (Oct 1, 2000 - month starts with 0)
var date2 = new Date(2000, 10, 1); (Nov 1, 2000 - month starts with 0)
dateDiff(date1, date2) -> 31
dateDiff(date1, date2, JST_FIELD_MONTH) -> 1
</pre><br>

<p>The
<a href="../api/JavaScriptUtil_functions.html#getMaxDay">getMaxDay</a> and
<a href="../api/JavaScriptUtil_functions.html#getFullYear">getFullYear</a>
functions do not manipulate dates, but are related to them.</p>
Examples:
<pre>getMaxDay(1, 2000) -> 29 (Feb, 2000 - month starts with 0 and 200 is a leap year)
getMaxDay(0, 2005) -> 31 (Jan, 2005 - month starts with 0)
getFullYear(0) -> 2000
getFullYear(99) -> 1999
getFullYear(0) -> 2000
</pre><br>

<br><br>
<hr>
<table width="100%">
    <tr>
        <td width="33%" align="left"><b>Previous:</b><br><a href="JavaScriptUtil_arrays.html">Working with arrays</a></td>
        <td width="34%" align="center"><a href="index.html">Table of Contents</a></td>
        <td width="33%" align="right"><b>Next:</b><br><a href="JavaScriptUtil_values.html">Retrieving and setting values on form fields and html elements</a></td>
    </tr>
</table>

</body>
</html>
